import java.util.Scanner;


public class MatrizRecursiva {
	
	private static int [][] C;


	public static int[][] matrixMultiplication(int[][]A, int[][]B){
		C = new int [A.length][B.length];
		if (A.length != B.length){
			return null;
		}else
			return matrixMultiplicationUtil(A,B,C,0,0,0);
	}	
	
	private static int [][] matrixMultiplicationUtil(int [][]A, int[][]B, int[][]C, int i, int j, int k){
		if (i == A.length){
			return C;
		}
		else{
			if (j == A.length){
				return matrixMultiplicationUtil(A, B, C, i+1, 0, 0);
			}else{
				if (k == A.length){
					return matrixMultiplicationUtil(A,B,C, i, j+1,0);
				}else{
					C[i][j] += A[i][k] * B[k][j];
					return matrixMultiplicationUtil(A,B,C,i,j,k+1);
				}
			}
		}	
	}
	
	
	public static void printMatrix(int [][] m){
		for (int i = 0; i < m.length; i++) {
			System.out.println();
			for (int j = 0; j < m.length; j++) {
				System.out.print(m[i][j] + " ");
			}
		}
		System.out.println();
	}
	
	
	public static void main(String[] args) {
		int [][] mA = {{1,2},{2,3}};
		int [][] mB = {{1,2},{2,3}};
		C = matrixMultiplication(mA, mB);
		printMatrix(C);
		int [][] mD = {{1,2,3},{2,3,5},{6,7,8}};
		int [][] mE = {{1,2,3},{2,3,4},{9,8,7}};
		C = matrixMultiplication(mD, mE);
		printMatrix(C);
		int [][] mF = {{1,2,4,5},{2,3,6,7},{5,6,7,8},{3,4,1,2}};
		int [][] mG = {{1,2,7,9},{11,4,6,10},{5,6,7,8},{3,4,1,2}};

		C = matrixMultiplication(mF, mG);
		printMatrix(C);
		
	
		
		
	}
	
	
	
	
	
	
	
	
	


}
